/**
 * Chrowety
 * options/menu.js
 */

var
menu = {};

menu.itens = [
	'#sections nav li[data-section', 
	'#sections section[data-section-content'
];

menu.init = function(tab)
{
	if( !cfg.isLogged() )
	{
		$(this.itens[0] + '="general"]').attr('disabled', true);
		$(this.itens[0] + '="interface"]').attr('disabled', true);
		$(this.itens[0] + '="alerts"]').attr('disabled', true);
		$(this.itens[0] + '="other"]').attr('disabled', true);
	}
	else
	{
		$(this.itens[0] + '="general"]').removeAttr('disabled');
		$(this.itens[0] + '="interface"]').removeAttr('disabled');
		$(this.itens[0] + '="alerts"]').removeAttr('disabled');
		$(this.itens[0] + '="other"]').removeAttr('disabled');
	}
	
	menu.show(tab);
	menu.bind();
    checkbox.init();
};

menu.bind = function()
{
    $(this.itens[0]+']').live('click', function()
    {
    	if( this.getAttribute('disabled') )
    	{
    		return false;
    	}
    	
        menu.show(this.getData('section'));
    });
};

menu.show = function( name )
{
    $(this.itens[0]+']').removeAttr('selected');
    $(this.itens[0]+'='+name+']').attr('selected', true);

    $(this.itens[1]+']').hide();
    $(this.itens[1]+'='+name+']').show();

    cfg.uiPref('optionsTab', name);
};



var
checkbox = {};

checkbox.itens = [
	'label[checkbox]', 
	'label[checkbox] input'
];

checkbox.init = function()
{
    $(this.itens[1]).each(checkbox.check);
    $(this.itens[1]).change(checkbox.check);
};

checkbox.check = function()
{
    var el = $(this.parentElement);

    if( this.checked )
    {
        el.addClass('checked', true);
    }
    else
    {
         el.removeClass('checked');
    }
};